package com.wswy.wzcx.ui.hold;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.thoughtbot.expandablerecyclerview.models.ExpandableGroup;
import com.thoughtbot.expandablerecyclerview.viewholders.GroupViewHolder;
import com.wswy.wzcx.R;
import com.wswy.wzcx.model.Genre;

/**
 * Created by wangduheng26 on 2018/1/23.
 * wangduheng26@gmail.com
 */

public class GenreViewHolder extends GroupViewHolder {
    public ImageView imageArrow;
    public TextView tvMonth;
    public TextView tvYear;
    public TextView tvContent;

    public GenreViewHolder(View itemView) {
        super(itemView);

        imageArrow = itemView.findViewById(R.id.group_arrow);
        tvMonth = itemView.findViewById(R.id.tv_month);
        tvYear = itemView.findViewById(R.id.tv_year);

        tvContent = itemView.findViewById(R.id.tv_content);
    }

    public void bind(ExpandableGroup group) {
        if (group instanceof Genre) {
            final Context context = tvMonth.getContext();
            tvMonth.setText(context.getString(R.string.month_args,group.getTitle()));
            tvYear.setText(context.getString(R.string.year_args,((Genre) group).year));
            tvContent.setText(context.getString(R.string.amount_args,((Genre) group).monthAmount));
        }
    }
    @Override
    public void expand() {
        animateExpand();
    }

    @Override
    public void collapse() {
        animateCollapse();
    }

    private void animateExpand() {

        imageArrow.animate().rotation(360).start();

    }

    private void animateCollapse() {
        imageArrow.animate().rotation(270).start();

    }

}
